Ext.onReady(function(){
	Ext.create('Ext.data.Store',{
		storeId:'userstore',
		fields:['id','name','age','email'],
		/*data:{'items':[
			{'name':'JJ','age':'21','email':'245423@qq.com'},
			{'name':'JonSnow','age':'22','email':'10123@qq.com'}
		]},*/
		proxy:{
			type:'ajax',
			url:'person.jsp',
			reader:{
				type:'json',
				root:'items'
			}
		},
		autoLoad:true
	});
	var grid = Ext.create('Ext.grid.Panel',{
		title:'grid_01',
		//frame:true,//渲染
		//forceFit:true,
		store:Ext.data.StoreManager.lookup('userstore'),
		columns:[
			{header:'ID',dataIndex:'id',hidden:true},
			{header:'Name',dataIndex:'name',field:'textfield'},
			{ header: 'Age', dataIndex: 'age'},
	        { header: 'Email', dataIndex: 'email',flex:1,field:{xtype:'textfield',allowBlank:false}}
		],
		tbar:[
			{text:'添加',handler:function(o){
				var grid1 = o.findParentByType("gridpanel");
				alert(grid1.getStore().getCount());
			}},'-',
			{text:'删除',handler:function(o){
				var grid1 = o.ownerCt.ownerCt;
				var data = grid1.getSelectionModel().getSelection();
				if(data.length == 0){
					Ext.Msg.alert("提示","至少选择一条数据");
				}else{
					var ids = [];
					Ext.Array.each(data,function(model){
						ids.push(model.get('id'));
					});
					//后台操作
					Ext.Ajax.request({
						url:"/ExtDemo/DemoServlet",
						params:{
							ids:ids.join(",")
						},
						method:"POST",
						timeout:2000,
						success:function(response,opts){
							Ext.Array.each(data,function(model){
								grid1.getStore().remove(model);
							});
						}
					});
				}
			}},'-',
			{text:'查看',handler:function(o){
				var grid1 = o.ownerCt.ownerCt;
				var data = grid1.getSelectionModel().getSelection();
				if(data.length == 0){
					Ext.Msg.alert("提示","至少选择一条数据");
				}else{
					
				}
			}},'-',
			{text:'修改'}
		],
		dockedItems:[{
			xtype:'pagingtoolbar',
			store:Ext.data.StoreManager.lookup('userstore'),
			dock: 'bottom',
			displayInfo:true
		}],
		plugins: [
	        Ext.create('Ext.grid.plugin.CellEditing', {
	            clicksToEdit: 1
	        })
	    ],
	    //selType: 'rowmodel',
		selType:'checkboxmodel',//设置选择模式
		multiSelect:true,//设置为多选
		height: 350,
	    width: 500,
	    renderTo: "grid"
	});
});